import 'package:hi_common/hi_common.dart';

class TimeUtil {
  static String hhmmss2hhmm(String time) {
    return RegExp(r'\w{2}:\w{2}').stringMatch(time);
  }

  //将数字转为时间
  //如0 ----> 00:00、1 ----> 01:00
  static String int2TimeString(int number) {
    return number == 24 ? '23:59' : '${StringUtil.singlePadLeftZero(number.toString())}:00';
  }

  //将时间字符穿转位数字
  //06:00:00 -> 6
  static int string2Int(String time) {
    if ('23:59:59'.contains(time)) {
      return 24;
    }

    return int.parse(time.split(':')[0]);
  }

  //【1，9】-》1:00-9:00
  static String timeArr2String(List<int> time) {
    String end = '';
    if (time[1] == 24) {
      end = '23:59';
    } else {
      end = '${time[1]}:00';
    }
    return '${time[0]}:00-$end';
  }
}
